import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/education/demand_research/get_personal_result_entity.dart';
import 'package:get/get.dart';

///调研结果（调查问卷）
class FindingsController extends GetxController {
  List<String> list = [];
  String? recommendation = '';

  @override
  void onInit() {
    super.onInit();
    //获取我的调研结果
    getPersonalResult();
  }

  ///获取我的调研结果
  void getPersonalResult() async {
    final res = await HttpUtil().generateGetRequest<GetPersonalResultEntity>(Interface.getPersonalResult, queryParameters: {
      'surveyId': Get.arguments['id'] ?? '',
    }).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        final GetPersonalResultEntity data = result.data!;
        //获取已选专题
        if (data.selectTypeList != null) {
          final List<GetPersonalResultSelectTypeList> questionValidityName = data.selectTypeList ?? [];
          for (var value in questionValidityName) {
            if (value == questionValidityName.last) {
              list.add(value.dictionaryLabel ?? '');
            } else {
              list.add('${value.dictionaryLabel}、');
            }
          }
        }
        //获取建议
        recommendation = result.data?.recommendation ?? '';
      }
    });
    update();
  }
}
